<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>登录验证</title>
</head>

<body>
登录验证……
<div id="app">
    {{ message }}
</div>
</body>

<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
    import axios from 'axios'
    var app = new Vue({
        el: '#app',
        data() {
            return{
                message: 'Hello Vue!'
            }

        },
        methods:{
            //读取cookie，需要注意的是cookie是不能存中文的，如果需要存中文，解决方法是后端先进行编码encode()，前端取出来之后用decodeURI('string')解码。（安卓可以取中文cookie，IOS不行）
            getCookie(name) {
                var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
                if (arr = document.cookie.match(reg)){
                    return (arr[2]);
                }else{
                    return false
                }
            },

            //设置cookie   name为cookie的名字，value是值，expiredays为过期时间（天数）
            setCookie (name, value, expiredays) {
                var exdate = new Date();
                exdate.setDate(exdate.getDate() + expiredays);
                document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
            },

            //删除cookie
            delCookie (name) {
                var exp = new Date();
                exp.setTime(exp.getTime() - 1);
                var cval = getCookie(name);
                if (cval != null)
                    document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
            }
        },
        created: function () {
            axios.get('http://admin.xmeihao.com/profile')
                .then(function (response) {
                    console.log(response);
                })
                .catch(function (response) {
                    console.log(response);
                });
            var arr = this.getCookie(`openid`)
            if (!arr){
                window.location.href="profile?backurl="+window.location.href;
            }
            this.message = arr

        }

    })
</script>

</html>